﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using RaSuperGrid.SuperGrid.Model;

namespace RaSuperGrid.SuperGrid.ViewModel
{
    class PRHeaderItemViewModel : NotifyPropertyChanged, IEditableObject, IDataErrorInfo
    {
        private PRHeader _model;
        private PRHeader _oldValue;

        public PRHeaderItemViewModel(PRHeader model)
        {
            _model = model;
        }

        public PRHeader Model
        {
            get { return _model; }
        }

        public string ColumnName
        {
            get { return _model.ColumnName; }
            set { if (value != _model.ColumnName) { _model.ColumnName = value; OnPropertyChanged("ColumnName"); } } 
        }

        public void BeginEdit()
        {
            _oldValue = _model.MakeCopy();
        }

        public void CancelEdit()
        {
            if (_oldValue != null)
            {
                _model = _oldValue;
                _oldValue = null;

                OnPropertyChanged("ColumnName");
            }
        }

        public void EndEdit()
        {
            _oldValue = null;
        }

        public string Error
        {
            get
            {
                return "";
            }
        }

        public string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case "ColumnName":
                        if (string.IsNullOrEmpty(columnName))
                            return "Column Name cannot be empty";
                        break;
                }

                return "";
            }
        }
    }
}
